﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FFTWSharp
{
    public class UnitConverter
    {
        /// <summary>
        /// 将加速度传感器的电压值转换为加速度值
        /// </summary>
        /// <param name="y"></param>
        /// <param name="sensitivity"></param>
        /// <returns></returns>
        public double[] mVtoms2(double[] y, double sensitivity)
        {
            List<double> yl = new List<double>(y);
            return yl.Select(s => s / sensitivity).ToArray();
        }

        /// <summary>
        /// 将加速度频谱纵坐标单位从dB转换为m/s2
        /// </summary>
        /// <param name="y">输入单位为dB的加速度频谱纵坐标</param>
        /// <param name="refer">参考基准</param>
        /// <returns>返回单位为m/s2的加速度频谱纵坐标</returns>
        public double[] dBtoms2(double[] y, double refer)
        {
            List<double> yl = new List<double>(y);
            return yl.Select(s => Math.Pow(10, s / 20) * refer).ToArray();
        }

        /// <summary>
        /// 将加速度频谱纵坐标单位从m/s2转换为dB
        /// </summary>
        /// <param name="y">单位为m/s2的加速度频谱纵坐标</param>
        /// <param name="refer">参考基准</param>
        /// <returns>单位为dB的加速度频谱纵坐标</returns>
        public double[] ms2todB(double[] y, double refer)
        {
            List<double> yl = new List<double>(y);
            return yl.Select(s => 20 * Math.Log10(s / refer)).ToArray();
        }
    }
}
